//引入express模块
const express=require('express');
//引入用户路由器模块
const slideshowRouter=require('./routes/slideshow.js');
const topsearchRouter=require('./routes/topsearch.js');
const particularsRouter=require('./routes/particulars.js');
const this_weekRouter=require('./routes/this_week.js');
const this_monthRouter=require('./routes/this_month.js');
const caiRouter = require('./routes/caipuRouter.js');
const JiankangshiliaoRouter=require('./routes/jiankangshiliao.js'); 
const ShipufenleiRouter=require('./routes/shipufenlei.js');
const cors=require('cors');
const xspRoutes=require('./routes/xsp.js');
//console.log(userRouter);
//创建WEB服务器
const app=express();
//设置端口
app.listen(3000,()=>{
	console.log('服务器启动成功');
})
app.use(express.urlencoded({
	extended:false
}));
// 托管静态资源
app.use(express.static('./public'));
app.use(cors())
//使用用户路由器，添加前缀/v1/slideshows
app.use('/v1/slideshows',slideshowRouter);
app.use('/v1/topsearchs',topsearchRouter);
app.use('/v1/particularss',particularsRouter);
app.use('/v1/this_weeks',this_weekRouter);
app.use('/v1/this_months',this_monthRouter);
app.use('/v1/caipu', caiRouter);
app.use('/v1/Jiankangshiliao',JiankangshiliaoRouter);
app.use('/v1/Shipufenlei',ShipufenleiRouter);
app.use('/v1/xsps',xspRoutes);

//添加错误处理中间件，拦截路由中传递过来的错误
app.use((err,req,res,next)=>{
 //err传递过来的错误
 console.log(err);
 //响应服务器端错误
 res.send({code:500,msg:'服务器端错误'});
});